import 'package:flutter/material.dart';
import 'package:flutter_bugly/flutter_bugly.dart';
import 'package:provide/provide.dart';
import 'package:qgchat/states/states_model/user.dart';

class Bugly extends StatefulWidget {
  final Widget child;
  Bugly({this.child, Key key}) : super(key: key);

  @override
  _BuglyState createState() => _BuglyState();
}

class _BuglyState extends State<Bugly> {
  @override
  void initState() {
    super.initState();
    FlutterBugly.init(
      androidAppId: "9d7d985816",
      iOSAppId: "ababa1abd4",
    );
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // 监听用户信息改变
    Provide.value<UserState>(context).addListener(() {
      final token = Provide.value<UserState>(context)?.info?.memberToken;
      if (token == null) return;
      FlutterBugly.setUserId(token);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: widget.child,
    );
  }
}
